/**
 * Created with JetBrains PhpStorm.
 * User: lunjiang
 * Date: 13-1-18
 * Time: 下午6:47
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    $(".date").datepicker({ dateFormat: "yy-mm-dd" });
    $(".detail").bind('click',function(){
        var obj= $(this);
        obj.parent().parent().children("td").css("border-top","1px solid #b9b9b9")
        obj.parent().parent().next().children("td").css("border-top","1px solid #b9b9b9");
         var bu_id = obj.attr("bu_id");
        var fid = obj.attr("fid");
        var type= 2;
        var start = $(".start").val();
        var end = $(".end").val();
        var className = "added"+ bu_id;//添加的列是className="added"加上事业部的id
        if(obj.hasClass("expended")){
            obj.removeClass("expended");
            $("."+ className).remove();
            obj.parent().parent().children("td").css("border-top","1px dotted #909090");
            obj.parent().parent().children("td:first").css("border-top","none");
            obj.parent().parent().next().children("td").css("border-top","1px dotted #909090");
            obj.parent().parent().next().children("td:first").css("border-top","1px solid white");
            return;
        }
        jQuery.ajax({
            async:true,
            url:url_dep_list,
            data:{type:type,fid:fid,bu_id:bu_id,start:start,end:end},
            type:'post',
            success:function (data) {
                var data = eval('(' + data + ')');
                if(data.errcode){//存在员工档案
                    /**
                     * 数据格式
                     * data
                     * data {status:1,data=[{city:'上海',dimissRate:'12%',voluntaryRate:10%,involuntaryRate:10%,belowLevel:10,aboveLevel:10,position1:1,position2:1,position3:1,
                     * position4:1,position5:1}]}
                     */
                    var strArray = [];
                    var arr = data.data;
                    for(var i in arr){
                        var tempData = arr[i];
                        var cityName = tempData.city_name;
                        var dimissRate = tempData.rate;
                        var voluntaryRate = tempData.leave_type_1;
                        var involuntaryRate = tempData.leave_type_2;
                        var belowLevel = tempData.pm_1;
                        var aboveLevel = tempData.pm_2;
                        var pos1 = tempData.job_time_1;
                        var pos2 = tempData.job_time_2;
                        var pos3 = tempData.job_time_3;
                        var pos4 = tempData.job_time_4;
                        var pos5 = tempData.job_time_5;
                        var pos6 = tempData.job_time_6;
                        var url = tempData.url;

                        var str = '';
                        str  = str + '<tr class='+className+'><td class="indentTD">&nbsp;</td><td class="city">'+cityName+"</td>";
                        str = str + "<td>"+dimissRate+ "</td>";
                        str = str + '<td><a class="blueColor" href="#">'+voluntaryRate+ "</td>";
                        str = str + '<td><a class="blueColor" href="#">'+involuntaryRate+ "</td>";
                        str = str + "<td>"+belowLevel+ "</td>";
                        str = str + "<td>"+aboveLevel+ "</td>";
                        str = str + "<td>"+pos1+ "</td>";
                        str = str + "<td>"+pos2+ "</td>";
                        str = str + "<td>"+pos3+ "</td>";
                        str = str + "<td>"+pos4+ "</td>";
                        str = str + "<td>"+pos5+ "</td>";
                        str = str + "<td>"+pos6+ "</td>";
                        if(url){
                            str = str +'<td><a target="_blank" href="'+url+'">查看详情</a></td>';
                        }else{
                            str = str +'<td></td>';
                        }


                        strArray.push(str);
                    }
                    var str = strArray.join('');
                    $(str).insertAfter(obj.parent().parent());
                    obj.addClass("expended");
                }
            }
        });

    });

});